<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\commands;

use app\util\Request;
use app\util\Util;
use yii\console\Controller;
use yii\console\ExitCode;

/**
 * This command echoes the first argument that you have entered.
 *
 * This command is provided as an example for you to learn how to create console commands.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class HelloController extends Controller
{
    /**
     * This command echoes what you have entered as the message.
     * @param string $message the message to be echoed.
     * @return int Exit code
     */
    public function actionIndex($message = 'hello world')
    {
        echo $message . "\n";

        return ExitCode::OK;
    }

    public function actionTest()
    {
        // $str = '{"r1_MerchantNo":"888111400005329","r2_OrderNo":"2021091616072176206","r3_Amount":"0.01","r4_Cur":"1","r5_Mp":"","r6_Status":"100","r7_TrxNo":"100221091669681357","r8_BankOrderNo":"100221091669681357","r9_BankTrxNo":"4200001210202109160871166467","ra_PayTime":"2021-09-16+16%3A07%3A29","rb_DealTime":"2021-09-16+16%3A07%3A29","rc_BankCode":"WEIXIN_GZH","hmac":"2d74f5f0076ac9ed21d0ad73c02dca2f"}';
        $str = '{"r1_MerchantNo":"888111400005329","r2_OrderNo":"2021091616371482755","r3_Amount":"0.01","r4_Cur":"1","r5_Mp":"","r6_Status":"100","r7_TrxNo":"100221091669705106","r8_BankOrderNo":"100221091669705106","r9_BankTrxNo":"4200001216202109163834555478","ra_PayTime":"2021-09-16+16%3A37%3A24","rb_DealTime":"2021-09-16+16%3A37%3A24","rc_BankCode":"WEIXIN_GZH","hmac":"273ae461ecf68d9a16030100fb57c70f"}';
        $arr = json_decode($str, true);
        $hmac = $arr['hmac'];

        $sign = 'fe2069d412d34894afdc83235d1b3181';

        // 2d74f5f0076ac9ed21d0ad73c02dca2f
        // 273ae461ecf68d9a16030100fb57c70f
        // ksort($arr);
        unset($arr['hmac']);
        $x = $this->signature($arr);
        $x = md5($x . $sign);

        var_dump($x, $hmac);

    }

    public function signature($params)
    {
        $str = '';
        foreach ($params as $param) {
            $str .= $param;
        }

        return $str;
    }

    public function actionGo()
    {
        // $url = 'https://www.chinaz.com/2022/0623/1411615.shtml';
        $url = 'http://m.titan007.com';
        $response = Request::get($url);
        var_dump($response);
    }

    public function actionY()
    {
        $url = 'http://yxsq.tydiy.com/web/reg/index.html?recommend=';
        for ($i = 0; $i < 99999; $i++) {
            $url .= $i;
            $res = Request::get($url);
            var_dump($res);
        }
    }

    public function actionSms()
    {
        $url = 'http://yxsq.tydiy.com/api/user/sendSms';
        $data = [
            // 'phone' => '18661652747',
            'phone' => '15913198695',
            'area_code' => '86',
        ];

        for ($i = 0; $i < 99999; $i++) {
            $res = Request::post($url, $data);
            var_dump($res);
        }
    }

    public function actionReg()
    {
        $url = 'http://yxsq.tydiy.com/api/user/register';
        $data = [
            'account' => '18661652747',
            'code' => '123456',
            'password' => '123456',
            'password_confirmation' => '123456',
            'recommend' => 'Y9TUCN',
        ];

        for ($i = 0; $i < 99999; $i++) {
            $res = Request::post($url, $data);
            var_dump($res);
        }
    }
}
